package com.example.forum.controller;

import com.example.forum.common.AppResult;
import com.example.forum.model.Board;
import com.example.forum.services.IBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/board")
@Slf4j
@Api(tags = "版块接口")
public class BoardController {

    //从配置文件中获得版块数，冒号后面是默认值
    @Value("${bit-forum.index.board-num:9}")
    private Integer indexBoardNum;
    @Resource
    private IBoardService boardService;;

    /**
     * 获取版块列表
     * @return
     */
    @ApiOperation("获取首页板块列表")
    @GetMapping("/topList")
    public AppResult<List<Board>> topList(){
        log.debug("主页版块个数："+indexBoardNum);
        //调用service
        List<Board> result = boardService.selectByNum(indexBoardNum);
        //返回结果
        return AppResult.success(result);
    }

    @ApiOperation("获取版块详情")
    @GetMapping("/getById")
    public AppResult<Board> getBoardInfo(@ApiParam("版块id") @RequestParam("id") @NonNull Long id){
        //调用service
        Board board = boardService.selectById(id);
        //返回结果
        return AppResult.success(board);
    }
}
